package com.ruoyi.find.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.find.mapper.FurnitureMapper;
import com.ruoyi.find.domain.Furniture;
import com.ruoyi.find.service.IFurnitureService;


/**
 * 家具信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-24
 */
@Service
public class FurnitureServiceImpl implements IFurnitureService 
{
    @Autowired
    private FurnitureMapper furnitureMapper;

    /**
     * 查询家具信息
     * 
     * @param furnitureId 家具信息主键
     * @return 家具信息
     */
    @Override
    public Furniture selectFurnitureByFurnitureId(Long furnitureId)
    {
        return furnitureMapper.selectFurnitureByFurnitureId(furnitureId);
    }

    /**
     * 查询家具信息列表
     * 
     * @param furniture 家具信息
     * @return 家具信息集合
     */
    @Override
    public List<Furniture> selectFurnitureList(Furniture furniture)
    {
        return furnitureMapper.selectFurnitureList(furniture);
    }

    /**
     * 新增家具信息
     * 
     * @param furniture 家具信息
     * @return 结果
     */
    @Override
    public int insertFurniture(Furniture furniture)
    {
        furniture.setCreateTime(DateUtils.getNowDate());
        return furnitureMapper.insertFurniture(furniture);
    }

    /**
     * 修改家具信息
     * 
     * @param furniture 家具信息
     * @return 结果
     */
    @Override
    public int updateFurniture(Furniture furniture)
    {
        furniture.setUpdateTime(DateUtils.getNowDate());
        return furnitureMapper.updateFurniture(furniture);
    }

    /**
     * 批量删除家具信息
     * 
     * @param furnitureIds 需要删除的家具信息主键集合
     * @return 结果
     */
    @Override
    public int deleteFurnitureByFurnitureIds(Long[] furnitureIds)
    {
        return furnitureMapper.deleteFurnitureByFurnitureIds(furnitureIds);
    }

    /**
     * 删除家具信息信息
     * 
     * @param furnitureId 家具信息主键
     * @return 结果
     */
    @Override
    public int deleteFurnitureByFurnitureId(Long furnitureId)
    {
        return furnitureMapper.deleteFurnitureByFurnitureId(furnitureId);
    }

    /**
     * 根据交易类型查询家具
     * 
     * @param transactionType 交易类型
     * @return 家具列表
     */
    @Override
    public List<Furniture> selectFurnitureByTransactionType(Integer transactionType)
    {
        return furnitureMapper.selectFurnitureByTransactionType(transactionType);
    }

    /**
     * 根据用户ID查询发布的家具
     * 
     * @param createBy 创建人
     * @return 家具列表
     */
    @Override
    public List<Furniture> selectFurnitureByCreateBy(String createBy)
    {
        return furnitureMapper.selectFurnitureByCreateBy(createBy);
    }

    /**
     * 搜索家具
     * 
     * @param keyword 关键词
     * @return 家具列表
     */
    @Override
    public List<Furniture> searchFurniture(String keyword)
    {
        return furnitureMapper.searchFurniture(keyword);
    }

    /**
     * 上架家具
     * 
     * @param furnitureId 家具ID
     * @return 结果
     */
    @Override
    public int upFurniture(Long furnitureId)
    {
        Furniture furniture = new Furniture();
        furniture.setFurnitureId(furnitureId);
        furniture.setStatus(1);
        furniture.setUpdateTime(DateUtils.getNowDate());
        return furnitureMapper.updateFurniture(furniture);
    }

    /**
     * 下架家具
     * 
     * @param furnitureId 家具ID
     * @return 结果
     */
    @Override
    public int downFurniture(Long furnitureId)
    {
        Furniture furniture = new Furniture();
        furniture.setFurnitureId(furnitureId);
        furniture.setStatus(0);
        furniture.setUpdateTime(DateUtils.getNowDate());
        return furnitureMapper.updateFurniture(furniture);
    }
}